package drds.server.sqlparser.sqlobject.expression;

import java.util.ArrayList;
import java.util.List;

import drds.server.sqlparser.visitor.Visitor;

/**
 * 
 * @author 曹正辉<330937205@qq.com>
 * 
 */
public class InListWithpartitionKey extends AbstractExpression {

	private boolean not = false;
	private Expression expression;
	private List<Expression> itemList = new ArrayList<Expression>();

	public InListWithpartitionKey() {

	}

	public InListWithpartitionKey(Expression expression) {
		this.setExpression(expression);
	}

	public InListWithpartitionKey(boolean not, Expression expression) {
		this.not = not;
		this.setExpression(expression);

	}

	public void setNot(boolean not) {
		this.not = not;
	}

	public boolean isNot() {
		return this.not;
	}

	public void setExpression(Expression expression) {
		if (expression != null) {
			expression.setParent(this);
		}

		this.expression = expression;
	}

	public Expression getExpression() {
		return this.expression;
	}

	public void setItemList(List<Expression> itemList) {
		this.itemList = itemList;
	}

	public List<Expression> getItemList() {
		return this.itemList;
	}

	protected void accept0(Visitor visitor) {
		if (visitor.visit(this)) {
			acceptChild(visitor, this.expression);
			acceptChild(visitor, this.itemList);
		}

		visitor.endVisit(this);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((expression == null) ? 0 : expression.hashCode());
		result = prime * result + (not ? 1231 : 1237);
		result = prime * result + ((itemList == null) ? 0 : itemList.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (o == null) {
			return false;
		}
		if (getClass() != o.getClass()) {
			return false;
		}
		InListWithpartitionKey other = (InListWithpartitionKey) o;
		if (expression == null) {
			if (other.expression != null) {
				return false;
			}
		} else if (!expression.equals(other.expression)) {
			return false;
		}
		if (not != other.not) {
			return false;
		}
		if (itemList == null) {
			if (other.itemList != null) {
				return false;
			}
		} else if (!itemList.equals(other.itemList)) {
			return false;
		}
		return true;
	}
}
